import threading

class Timer(object):
	"""My cute timer class"""
	timers = []
	hours = 0
	minutes = 0
	seconds = 0
	
	def __init__(self, callback):
		self.callback = callback
		self.timer = None
		
	def __call__(self):
		"""Timer tick calling"""
		Timer.seconds += 1
		if Timer.seconds > 59:
			Timer.seconds = 0
			Timer.minutes += 1
		if Timer.minutes > 59:
			Timer.minutes = 0
			Timer.hours += 1
		self.callback(Timer.hours, Timer.minutes, Timer.seconds)
		self.start()
		
	def start(self):
		"""Start timer"""
		if self.timer:
			self.timer.cancel()
		self.timer = threading.Timer(1.0, self)
		Timer.timers.append(self.timer)
		self.timer.start()
		
	@staticmethod
	def set_time(hours, minutes, seconds):
		Timer.hours = hours
		Timer.minutes = minutes
		Timer.seconds = seconds
		
	@staticmethod
	def zero():
		Timer.set_time(0, 0, 0)
			
	@staticmethod
	def stop():
		"""Stop all active timers"""
		for timer in Timer.timers:
			timer.cancel()
		Timer.timers = []
